package com.wy.controller;

import com.wy.Service.RoomService;
import com.wy.pojo.Danyuan;
import com.wy.pojo.Role;
import com.wy.pojo.Room;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/room")
@CrossOrigin
public class RoomController {
    @Resource
    private RoomService roomServer;

    String msg;

    @GetMapping("/listAll")
    public List<Room> search(){
        return roomServer.searchAll();
    }

    @GetMapping("/list")
    public List<Room>seach(Integer danyuanid){
        return roomServer.searchidAll(danyuanid);
    }

    @GetMapping("/delete")
    public String delete(Integer id){
        try{
            roomServer.del(id);
            msg="删除成功";
        }catch (Exception e){
            msg="删除失败";
        }
        return msg;
    }

    @GetMapping("/add")
    public String add(Room room){
        try{
            room.setStart(1);
            roomServer.add(room);
            msg="添加成功";
        }catch (Exception e){
            msg="添加失败";
        }
        return msg;
    }
    @GetMapping("/update")
    public String update(Room room){
        try{
            roomServer.update(room);
            msg="修改成功";
        }catch (Exception e){
            msg="修改失败";
        }
        return msg;
    }
}
